/*
 * UltrasoundSensor.java
 *
 * Created on April 25, 2008, 2:08 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.ncsu.external_sensors;

import com.sun.spot.core.resources.ResourceUnavailableException;
import com.sun.spot.edemo.io.IOPin;

/**
 *
 * @author me
 */
public abstract class UltrasoundSensor implements IRobotSensor {
    public static final int METERS = 0;
    public static final int CENTIMETERS = 1;
    public static final int MILLIMETERS = 2;
    public static final int INCHES = 3;
    protected static final double[] UNITS_PER_METER = {1, 100, 1000, 39.3700787401575};
    protected int units = 0;
    protected IOPin input;
    
    /**
     * Sets the unit of length for calculating distance for this sensor
     * @param index - the public index from this class that corresponds to the desired unit of measure
     */
    public void setUnitOfLength(int index) {
        units = index;
    }
    
    /**
     * @return the distance of the nearest object, in the selected unit of length
     * @throws ResourceUnavailableException if sensor cannot be detected
     */
    public abstract double getConvertedValue() throws ResourceUnavailableException;
    
    /**
     * @return the time in milliseconds of the input pulse from the sensor.  This value is the time it takes for
     * @throws ResourceUnavailableException if sensor cannot be detected
     */
    public abstract long getRawValue() throws ResourceUnavailableException;
    
    public boolean equals(Object o) {
        if (o.getClass() != this.getClass()) {
            return false;
        }
        return input.equals(((UltrasoundSensor)o).input);
    }
}
